﻿using Phoenix.Diagnostics;
using Phoenix.Frames;
using Phoenix.Framework;

namespace Phoenix.ActionResults
{
    public class ReturnResultActionResult : ActionResult, IHaveInvokeCompletedSteps
    {
        readonly object result;

        public ReturnResultActionResult(ControllerActionContext context, object result) : base(context)
        {
            this.result = result;
        }

        public override void Execute(IContentFrame targetFrame)
        {
        }

        public void InvokeComplete()
        {
            var taskCompletionSource = Context.CompletionSource;
            if (taskCompletionSource == null)
                Trace.WriteWarning(this, ()=>"Cannot return result, no completion source. Make sure you use InvokeActionWithResult rather than InvokeAction");
            else
                taskCompletionSource.SetResult(result);
        }
    }
}